
#include "cocos2d.h"
#include "Director/PlayerPerformance.h"

#include "config.h"
#include "src/TestMacros.h"
#include "src/CheckMacros.h"
#include "src/TestRunner.h"
#include "src/TimeConstraint.h"
#include "src/ReportAssert.h"

using namespace cocos2d;
using namespace UnitTest;

SUITE(PlayerPerformance)
{

	TEST(PlayerPerformanceInitialized)
	{
		PlayerPerformance* myPlayerPerformance = new PlayerPerformance(10.0);

		CHECK_EQUAL(myPlayerPerformance->getGameDuration(), 0);

		//cleanup
		delete myPlayerPerformance;
		myPlayerPerformance = 0;
	}

	TEST(PlayerPerformanceUpdate)
	{
		float updateAmount = 2.0;
		PlayerPerformance* myPlayerPerformance = new PlayerPerformance(10.0);

		myPlayerPerformance->update(updateAmount);

		CHECK_EQUAL(myPlayerPerformance->getGameDuration(), updateAmount);
		CHECK_CLOSE(myPlayerPerformance->getAliveDuration(), updateAmount/60.0, 0.01);

		//cleanup
		delete myPlayerPerformance;
		myPlayerPerformance = 0;
	}

	TEST(PlayerPerformanceReduceDifficulty)
	{
		PlayerPerformance* myPlayerPerformance = new PlayerPerformance(10.0);

		CHECK_EQUAL(myPlayerPerformance->isDifficultyReduced(), false);

		myPlayerPerformance->reduceDifficulty();

		CHECK_EQUAL(myPlayerPerformance->isDifficultyReduced(), true);
		CHECK_EQUAL(myPlayerPerformance->isDifficultyReduced(), false);

		//cleanup
		delete myPlayerPerformance;
		myPlayerPerformance = 0;
	}

	TEST(PlayerPerformanceGetPerformance)
	{
		PlayerPerformance* myPlayerPerformance = new PlayerPerformance(10.0);

		CHECK_EQUAL(myPlayerPerformance->getPerformanceLevel(), 1);

		int previousValue = myPlayerPerformance->getPerformanceLevel();

		myPlayerPerformance->update(50.0);
		bool isIncreased = myPlayerPerformance->getPerformanceLevel() > previousValue;
		CHECK_EQUAL(isIncreased, true);
		previousValue = myPlayerPerformance->getPerformanceLevel();

		myPlayerPerformance->update(500.0);
		isIncreased = myPlayerPerformance->getPerformanceLevel() > previousValue;
		CHECK_EQUAL(isIncreased, true);

		//cleanup
		delete myPlayerPerformance;
		myPlayerPerformance = 0;
	}


}
